In the push data consumption model, you write a method that fulfills the OPC Write requests. The OPC Wizard calls this method (pushes the data) when needed.
This is the more common data consumption model.
Your task as a developer is to provide the code for handling the Write request by either adding an event handler for the Write Event, or overriding the OnWrite Method. The code for handling the data push can be attached to each data variable separately, or you can use a common code on some higher level in the tree of the server nodes - for example, a folder can have code that handles all Writes for the data variables contained in the folder.
In order to indicate that you have handled the Write request, your code will call the HandleAndReturn Method on the event arguments object. Note that if you use the extension methods for configuration of data variables, the event handler added by the extension methods already does this for you.
The OPC Wizard provides extension methods that allow you to define data variables that use the push data consumption model easily, without having to deal with method overrides, or handle events. This is described in the Data Variable Configuration article. Typically, you will use some overload of the WriteFunction, WriteValueAction or WriteValueFunction method to configure the data variable for the push data consumption model. With these methods, you use .NET functions (Func<...,TResult> Delegate) or actions (Action Delegate) to specify the code that handles the request. The following example illustrates the use of the WriteValueAction method.
The data variable can also be made write-only, if that is your requirement. Example: Examples - Server OPC UA - Write-only value implemented using an action.
How do you choose between these three extension methods?
The following example illustrates the use of the WriteValueFunction method for a data variable that forces its value to be within certain range.
If the data variable should also support writing of the status code or timestamp (or both), you will use the WriteFunction method, as illustrated in the following example.
If your OPC server has groups of data variables with basically the same behavior, and organized in such a way that it corresponds to the node space hierarchy, you would probably want to specify the behavior just once, e.g. on the level of the folder that holds all data variables of the same kind. In such case, you cannot use the extension methods for data variable configuration (described above), and need to define the behavior by handling the Write Event, or overriding the OnWrite Method, on the higher level - in our example, the level of the folder. The following examples illustrate these approaches.
Example: Examples - Server OPC UA - Implement variable writing on folder level, with an event
Example: Examples - Server OPC UA - Implement variable writing on folder level, with inheritance
If the actual Write operation (to your underlying system or connected system) is performed at some later time and not inside the handler for the Write request, you must indicate this to the OPC UA client using a dedicated status code, with code bits GoodCompletesAsynchronously. The following example illustrates how it is done.
See Variable Data Type Considerations.